package com.ruoyi.app.controller;

import com.ruoyi.system.domain.TGoodsType;
import com.ruoyi.system.domain.TOrder;
import com.ruoyi.system.domain.User;
import com.ruoyi.system.service.ITOrderService;
import com.ruoyi.utils.AjaxResult;
import com.ruoyi.utils.AppUserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "小程序端-商品订单")
@RestController
@RequestMapping("/app/order")
public class GoodsOrderController {

    @Autowired
    private ITOrderService tOrderService;


    @ApiOperation("获取用户购物车信息")
    @PostMapping("/getShoppingCart")
    public AjaxResult<TOrder> getShoppingCart(TOrder tOrder) {
        String appUser = AppUserUtils.getAppUserId();
        tOrder.setUserId(appUser);
        tOrder.setShoppingCart(1);//3是存在购物车未支付
        List<TOrder> list =  tOrderService.selectTOrderList(tOrder);
        return AjaxResult.success(list);
    }

    @ApiOperation("添加商品到购物车")
    @PostMapping("/saveShoppingCart")
    public AjaxResult saveShoppingCart(List<TOrder> tOrders) {
        String id = AppUserUtils.getAppUserId();
        tOrderService.saveShoppingCart(tOrders,id);
        return AjaxResult.success();
    }

    @ApiOperation("购物车商品结算")
    @GetMapping("/settleShoppingCart/{ids}")
    public AjaxResult settleShoppingCart(@PathVariable("ids") Long ids) {
//        return tOrderService.settleShoppingCart(ids);
        return null;
    }
}
